import api from './index'
import { axios } from '@/utils/request'
import Vue from 'vue'
import qs from 'qs'
/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return axios({
    url: 'base/login/token',
    transformRequest: [function(data, headers) {
      return qs.stringify({ ...data })
    }],
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha(parameter) {
  return axios({
    url: api.SendSms,
    method: 'post',
    transformRequest: [function(data, headers) {
      return qs.stringify({ ...data })
    }],
    data: parameter
  })
}

export function getInfo() {
  return axios({
    url: 'base/current/user',
    method: 'get'
  })
}

export function getCurrentUserNav(token) {
  return axios({
    url: '/user/nav',
    method: 'get'
  })
}


export function logout() {
  let token = Vue.ls.get('Access-Token')
  return axios({
    url: 'base/logout/token',
    method: 'post',
    transformRequest: [function(data, headers) {
      return qs.stringify({ ...data })
    }],
    data: {
      token: token
    }
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step(parameter) {
  return axios({
    url: api.twoStepCode,
    method: 'post',
    transformRequest: [function(data, headers) {
      return qs.stringify({ ...data })
    }],
    data: parameter
  })
}

/**
 * 获取登录用户菜单权限
 */
export const getUserMenu = () => {
  return axios({
    url: 'base/current/user/menu',
    method: 'get'
  })
}

/**
 * 获取登录用户按钮权限
 */
export const getUserAuthBtns = () => {
  return axios({
    url: 'base/bus/srm/system/action/user/list',
    method: 'get'
  })
}